package com.wpen.unit.security;

/**
 * 密码加密封装
 * 
 * @author Admin
 *
 */
public class PasswordUtil {
    private final static String snHsPwd = "1qaz2wsx3edc4rfv";
    private final static String snHePwd = "0okm8uhb9ijn7ygv";
    private static final String encoding = "UTF-8";
    private static SHA1 sha1 = null;
    private static PasswordUtil instance = new PasswordUtil();

    private PasswordUtil() {
    }

    public static synchronized PasswordUtil getInstance() throws Exception {
        if (sha1 == null)
            sha1 = new SHA1();
        if (instance == null)
            return new PasswordUtil();
        return instance;
    }

    public String encodePwd(String userId, String password) throws Exception {
        String instr = snHsPwd + password + userId + snHePwd;
        byte[] indata = instr.getBytes(encoding);
        byte[] outdata = sha1.digest(indata, 0, indata.length);
        String hex_str = Base16.encode(outdata);
        return hex_str;
    }

    public static void main(String[] args) throws Exception {
        System.out.println(PasswordUtil.getInstance().encodePwd("admin", "123456"));
    }

}
